package com.zhaoyd.uaademo.service;

import com.zhaoyd.uaademo.core.orm.BaseMapper;
import com.zhaoyd.uaademo.core.orm.BaseService;
import com.zhaoyd.uaademo.entity.SysResource;
import com.zhaoyd.uaademo.enums.ResourceTypeEnum;
import com.zhaoyd.uaademo.mapper.SysResourceMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * @author zhaoyd
 * @date 2020-10-31 19:03
 */
@Service
public class SysResourceService extends BaseService<SysResource> {
    @Resource
    private SysResourceMapper sysResourceMapper;
    @Override
    protected BaseMapper<SysResource> dao() {
        return sysResourceMapper;
    }

    public List<SysResource> listResourceByUser(Integer userId){
        return sysResourceMapper.listResourceByUser(userId);
    }

    public Set<String> listResourceCodeByUser(Integer userId){
        List<SysResource> sysResources = this.listResourceByUser(userId);
        Set<String> resources = new HashSet<>();
        sysResources.forEach(sysResource -> {
            if(sysResource.getType()== ResourceTypeEnum.资源.getCode()){
                resources.add(sysResource.getResource());
            }
        });
        return resources;
    }
}
